﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IFRS.Web;
using System.Data;
using IFRS.DataAccess.DAL;
using IFRS.Models;
using IFRS_Global;

public partial class IFRS_WIN11_3V : PageBase
{
    #region "---------- Property -----------"

    private readonly SPR_FCD dal_fcd = new SPR_FCD();
    private FCD fcd = new FCD();

    #endregion

    #region "---------- Events -----------"

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!(Page.IsPostBack || Page.IsCallback))
        {
            this.ViewMenu();
            BindControlData();
            SetErrorMessage();
            BindData();
        }
        else
            ClientScript.RegisterHiddenField("isPostBack", "1");
    }

    protected void btnCANCEL_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/IFRS/WIN11_1S.aspx");
    }

    #endregion

    #region "---------- Methods -----------"

    private void ViewMenu()
    {
        this.MenuTitleBar = Resources.ifrsResource.View + Resources.ifrsMenu.WIN11;
    }

    private void SetErrorMessage()
    {
    }

    private void BindControlData()
    {
        ddlDAY_COUNT_METHOD.SetData(DDL_TYPE.DayCountMethod, "", false, true);
        ddlINTEREST_PAYMENT_FREQTIMEBASE.SetData(DDL_TYPE.PaymentFrequencyTimeBase, "", false, true);
        ddlPAYMENT_CONDITION.SetData(DDL_TYPE.PaymentCondition, "", false, true);

        SetControlReadOnly(form_control);
    }

    private void BindData()
    {
        if (Request.QueryString["id"] == null)
            return;

        int ID = Convert.ToInt32(Request.QueryString["id"].ToString());
        DataTable dtFCD = dal_fcd.SEARCH_BYID(ID);
        List<FCD> FCDList = new List<FCD>();
        ConvertHelper.ConvertDataTableToObject(dtFCD, FCDList);
        if (dtFCD.Rows.Count > 0)
        {
            hidFCDID.Value = FCDList[0].FCDID.ToString();
            txtTRANSACTION_DATE.Text = FCDList[0].TransactionDate.DateToString();
            txtACCOUNT_NO.Text = FCDList[0].AccountNo;
            txtGL_ACCOUNT.Text = FCDList[0].GLAccount;
            hidGL_ACCOUNT.Value = FCDList[0].GLAccount;
            txtCOST_CENTER.Text = FCDList[0].COST_CENTER_NM;
            hidCOST_CENTER.Value = FCDList[0].CostCenter;
            txtSTARTED_DATE.Text = FCDList[0].StartedDate.DateToString();
            txtEND_DATE.Text = FCDList[0].EndDate.DateToString();
            txtCURRENCYCODE_NAME.Text = FCDList[0].CurrencyCode;
            hidCURRENCY_CODE.Value = FCDList[0].CurrencyCode;
            txtUNPAIDCAPITAL.Text = FCDList[0].UnpaidCapital.ToString();
            txtINTEREST_RATE.Text = FCDList[0].InterestRate.ToString();
            ddlDAY_COUNT_METHOD.SelectedValue = FCDList[0].DayCountMethodID.ToString();
            txtINTEREST_PAYMENT_FREQ.Text = FCDList[0].InterestPaymentFreq.ToString();
            ddlINTEREST_PAYMENT_FREQTIMEBASE.SelectedValue = FCDList[0].InterestPaymentFreqTimeBase;
            ddlPAYMENT_CONDITION.SelectedValue = FCDList[0].PaymentConditionID.ToString();
            txtCUSTOMER.Text = FCDList[0].CustomerCode;
            hidCUSTOMER_ID.Value = FCDList[0].CustomerID.ToString();
            txtIS_CONFIRMED.Text = (bool)FCDList[0].IsConfirmed ? Resources.ifrsField.CONFIRM : Resources.ifrsField.CREATE;
        }
    }

    #endregion
}